<script setup>
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/auth'

const authStore = useAuthStore()
const router = useRouter()

const isLoggedIn = computed(() => authStore.isLoggedIn)
const username = computed(() => authStore.username)

// 登出
const handleLogout = () => {
  authStore.logout()
  router.push('/login')
}
</script>

<template>
  <div class="user-status">
    <div v-if="isLoggedIn" class="user-status-logged-in">
      <span class="welcome">欢迎，{{ username }}</span>
      <button class="logout-btn" @click="handleLogout">退出登录</button>
    </div>
    <div v-else class="user-status-logged-out">
      <button class="login-btn" @click="router.push('/login')">登录</button>
      <button class="register-btn" @click="router.push('/login?register=true')">注册</button>
    </div>
  </div>
</template>

<style scoped>
.user-status {
  display: flex;
  align-items: center;
}

.user-status-logged-in,
.user-status-logged-out {
  display: flex;
  align-items: center;
  gap: 12px;
}

.welcome {
  font-weight: 500;
  color: #333;
}

button {
  padding: 8px 16px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s ease;
}

.logout-btn {
  background-color: #f0f0f0;
  color: #555;
}

.logout-btn:hover {
  background-color: #e0e0e0;
}

.login-btn {
  background-color: #00c389;
  color: white;
}

.login-btn:hover {
  background-color: #00b07b;
}

.register-btn {
  background-color: #ff5a5a;
  color: white;
}

.register-btn:hover {
  background-color: #ff3939;
}
</style> 